<!--# include virtual="/admin/common/html/header.html"-->
<body>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
		<a class="btn btn-primary radius" onclick="add(null)" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i>新增信息</a>
		<a class="btn btn-success radius r" style="line-height:1.6em;" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
		<!--<a class="btn btn-primary radius"  id="input"  href="javascript:;">
			<i class="Hui-iconfont"  style="font-size: 18px;">&#xe645;</i>导入
		</a>-->
		<!--<a class="btn btn-link" href="/admin/modules/datashare/info/moban.xlsx" target="_blank">下载导入模板</a>-->
		</span>
	</div>
	<div class="mt-20">
		<table id="firm-post-list" class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c" id="title"></tr>
			</thead>
			<tbody>				
			</tbody>
		</table>
	</div>
</div>
<!--# include virtual="/admin/common/html/_footer.html"-->


<script type="text/javascript">
var base=GetQueryString("name");
var costId=GetQueryString("costId");
var individualId=GetQueryString("individualId");
let nameJSON={
	"individualBudget":['序号','单位工程名称','暂估价','安全文明施工费','规费'],
	"unitBudget":['序号','汇总内容','金额','暂估价'],
	"otherSummary":['序号','项目名称','金额','结算金额','备注'],
	"billtaxList":['序号','项目名称','计算基础','取费基数','计算费率','金额'],
	"unitmaterialSummary":['序号','编码','名称及规格','单位','数量','单价','合价','品牌','厂家'],
	"totalMeasures":['序号','项目编码','项目名称','计算基础','费率','金额','调整费率','调整后金额','备注'],
	"dataInfo":['序号','分部编码','分部名称','项目编码','项目名称','项目特征描述','计量单位','工程量','综合单价','综合合价'],
	"dataInfoColumns":['serialnumber','categoryCode','categoryName','code','name','description','unit','amount','price','total']
}
let columnsJSON=[];
var url="";
$(function() {
	var html ="";
	for(j of nameJSON[base]){
		html +='<th width="10%">'+j+'</th>';
	}
	html +='<th width="5%">操作</th>';
	$("#title").html(html);
	
	if(base == "dataInfo"){
		url="/guidance_service/front/data/info/search.do";
		for(m of  nameJSON.dataInfoColumns){
			columnsJSON.push({
				data: m,
				render: function(data) {return data || "";}
			});
		}
		columnsJSON.push({
			data: "infoId",
			render: function(data, type, row) {
				return	'<a style="text-decoration:none" class="ml-5" onClick=\'update()\' href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>' +
					'<a style="text-decoration:none" class="ml-5" onClick="del('+individualId+',this)" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>';
			}
		});
	}else{
	   url="/guidance_service/front/data/individual/getBase.do";
	   for(m of  nameJSON[base]){
			columnsJSON.push({
				data: m,
				render: function(data) {return data || "";}
			});
		}
		columnsJSON.push({
			data: "individualId",
			render: function(data, type, row) {
				return	'<a style="text-decoration:none" class="ml-5" onClick=\'update()\' href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>' +
					'<a style="text-decoration:none" class="ml-5" onClick="del('+individualId+',this)" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>';
			}
		});
	}
	
});
</script>
<script type="text/javascript">
$(function() {
	var user = {
		getQueryCondition: function(data) {
			var param = {};
			param.costId = GetQueryString("costId");
			param.pageNumber = Number(data.start/data.length)+1  || 1;
			param.pageSize = data.length   || 100;
			param.state=$("#state").val();
			param.draw = 1;
			return param;
		}
	};
    var dataTable = $("#firm-post-list").zosoftDataTable({
    	searchButton:"#searchButton",
		ajax: function(data, callback) { //ajax配置为function,手动调用异步查询
			$.post(url, 
					{base:base,
					 costId:costId,
					 individualId:individualId
					},function(result) {
						let  data =result.data;
						let  mydata ={};
						var returnData = {};
						if(Array.isArray(data)){
							for(var d of data){
								mydata= d[base];
								mydata = JSON.parse(mydata);
							}
							returnData.recordsTotal = mydata.length;
							returnData.recordsFiltered = mydata.length;
							returnData.data = mydata;
						}else{
							mydata=data;
							returnData.recordsTotal = mydata.totalRow;
							returnData.recordsFiltered = mydata.totalRow;
							returnData.data = mydata.list;
						}
						callback(returnData);
			});
		},
		columns: columnsJSON
	});
});
</script>
<script type="text/javascript">
function del(individualId,obj){     /*zosoft-删除*/
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '/guidance_service/front/data/individual/logicDelete.do',
			dataType: 'json',
			data:{individualId:individualId},
			success: function(data){
				if(data.data.result){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:1,time:1000},function(){
					});
				}
			},
			error:function(data) {
				console.log(data.msg,function(){
				});
			},
		});		
	});
}
function update(individualId,individualName,individualCode){
	layer.myprompt(
		{"title": '编辑',
		 "promName":["工程专业","专业编码"],
		 "value":[individualName,individualCode]}, 
		 function(text, index){
			var data ={
				"individualName":text[0].trim(),
				"individualCode":text[1].trim(),
				"individualId":individualId
			}
			$.post("/guidance_service/front/data/individual/update.do",
			       data,
			       function(result){
					if(result.resultCode == 200){
					    layer.close(index);
                        location.replace(location.href);
					}else{
						layer.msg(result.message,{icon:2,time:1000},function(){
							layer.close(index);
							location.replace(location.href);
						});
					}
			});
		});
	
}

function add(objs){
	layer.myprompt(
		{"title": '新增',
		 "promName":["工程专业","专业编码"],
		 "value":[]
		 },
		 function(text, index){
			var data ={
				"individualName":text[0].trim(),
				"individualCode":text[1].trim(),
				"costId":GetQueryString("costId")
			}
			$.post("/guidance_service/front/data/individual/add.do",
			       data,
			       function(result){
					if(result.resultCode == 200){
					    layer.close(index);
					    location.replace(location.href);
					}else{
						layer.msg(result.message,{icon:2,time:1000},function(){
							layer.close(index);
							location.replace(location.href);
						});
					}
			});
		});
	
}
</script>
</body>
</html>